Trabb Pardo–Knuth Algorithm
   HOME

TheInfoList



OR:

The TPK algorithm is a simple
program Program, programme, programmer, or programming may refer to: Business and management * Program management, the process of managing several related projects * Time management * Program, a part of planning Arts and entertainment Audio * Progra ...
introduced by
Donald Knuth Donald Ervin Knuth ( ; born January 10, 1938) is an American computer scientist, mathematician, and professor emeritus at Stanford University. He is the 1974 recipient of the ACM Turing Award, informally considered the Nobel Prize of computer sc ...
and Luis Trabb Pardo to illustrate the evolution of computer
programming language A programming language is a system of notation for writing computer programs. Most programming languages are text-based formal languages, but they may also be graphical. They are a kind of computer language. The description of a programming ...
s. In their 1977 work "The Early Development of Programming Languages", Trabb Pardo and Knuth introduced a small program that involved
arrays An array is a systematic arrangement of similar objects, usually in rows and columns. Things called an array include: {{TOC right Music * In twelve-tone and serial composition, the presentation of simultaneous twelve-tone sets such that the ...
, indexing, mathematical
function Function or functionality may refer to: Computing * Function key, a type of key on computer keyboards * Function model, a structured representation of processes in a system * Function object or functor or functionoid, a concept of object-oriente ...
s,
subroutine In computer programming, a function or subroutine is a sequence of program instructions that performs a specific task, packaged as a unit. This unit can then be used in programs wherever that particular task should be performed. Functions may ...
s, I/O, conditionals and
iteration Iteration is the repetition of a process in order to generate a (possibly unbounded) sequence of outcomes. Each repetition of the process is a single iteration, and the outcome of each iteration is then the starting point of the next iteration. ...
. They then wrote implementations of the algorithm in several early programming languages to show how such concepts were expressed. To explain the name "TPK", the authors referred to
Grimm's law Grimm's law (also known as the First Germanic Sound Shift) is a set of sound laws describing the Proto-Indo-European (PIE) stop consonants as they developed in Proto-Germanic in the 1st millennium BC. First systematically put forward by Jacob Grim ...
(which concerns the consonants 't', 'p', and 'k'), the sounds in the word "typical", and their own initials (Trabb Pardo and Knuth). In a talk based on the paper, Knuth said:


The algorithm

Knuth describes it as follows:Donald Knuth, ''TPK in INTERCAL'', Chapter 7 of ''Selected Papers on Fun and Games'', 2011 (p. 41) In pseudocode: ask for 11 numbers to be read into a sequence ''S'' reverse sequence ''S'' for each ''item'' in sequence ''S'' call a function to do an operation if ''result'' overflows alert user else print ''result'' The algorithm reads eleven numbers from an input device, stores them in an array, and then processes them in reverse order, applying a user-defined function to each value and reporting either the value of the function or a message to the effect that the value has exceeded some threshold.


Implementations


Implementations in the original paper

In the original paper, which covered "roughly the first decade" of the development of high-level programming languages (from 1945 up to 1957), they gave the following example implementation "in a dialect of
ALGOL 60 ALGOL 60 (short for ''Algorithmic Language 1960'') is a member of the ALGOL family of computer programming languages. It followed on from ALGOL 58 which had introduced code blocks and the begin and end pairs for delimiting them, representing a k ...
", noting that ALGOL 60 was a later development than the languages actually discussed in the paper: TPK: begin integer i; real y; real array a :10 real procedure f(t); real t; value t; f := sqrt(abs(t)) + 5 × t ↑ 3; for i := 0 step 1 until 10 do read(a ; for i := 10 step -1 until 0 do begin y := f(a ; if y > 400 then write(i, 'TOO LARGE') else write(i, y); end end TPK. As many of the early high-level languages could not handle the TPK algorithm exactly, they allow the following modifications: * If the language supports only integer variables, then assume that all inputs and outputs are integer-valued, and that sqrt(x) means the largest ''integer'' not exceeding \sqrt. * If the language does not support alphabetic output, then instead of the string 'TOO LARGE', output the number 999. * If the language does not allow ''any'' input and output, then assume that the 11 input values a_0, a_1, \ldots, a_ have been supplied by an external process somehow, and the task is to compute the 22 output values 10, f(10), 9, f(9), \ldots, 0, f(0) (with 999 replacing too-large values of f(i)). * If the language does not allow programmers to define their own functions, then replace f(a with an expression equivalent to \sqrt + 5x^3. With these modifications when necessary, the authors implement this algorithm in
Konrad Zuse Konrad Ernst Otto Zuse (; 22 June 1910 – 18 December 1995) was a German civil engineer, pioneering computer scientist, inventor and businessman. His greatest achievement was the world's first programmable computer; the functional program-c ...
's
Plankalkül Plankalkül () is a programming language designed for engineering purposes by Konrad Zuse between 1942 and 1945. It was the first high-level programming language to be designed for a computer. ''Kalkül'' is the German term for a formal system ...
, in Goldstine and
von Neumann Von Neumann may refer to: * John von Neumann (1903–1957), a Hungarian American mathematician * Von Neumann family * Von Neumann (surname), a German surname * Von Neumann (crater), a lunar impact crater See also

* Von Neumann algebra * Von Ne ...
's flow diagrams, in
Haskell Curry Haskell Brooks Curry (; September 12, 1900 – September 1, 1982) was an American mathematician and logician. Curry is best known for his work in combinatory logic. While the initial concept of combinatory logic was based on a single paper by ...
's proposed notation, in
Short Code codes, or short numbers, are short digit sequences, significantly shorter than telephone numbers, that are used to address messages in the Multimedia Messaging System (MMS) and short message service (SMS) systems of mobile network operators. I ...
of
John Mauchly John William Mauchly (August 30, 1907 – January 8, 1980) was an American physicist who, along with J. Presper Eckert, designed ENIAC, the first general-purpose electronic digital computer, as well as EDVAC, BINAC and UNIVAC I, the first co ...
and others, in the Intermediate Program Language of
Arthur Burks Arthur Walter Burks (October 13, 1915 – May 14, 2008) was an American mathematician who worked in the 1940s as a senior engineer on the project that contributed to the design of the ENIAC, the first general-purpose electronic digital computer. ...
, in the notation of
Heinz Rutishauser Heinz Rutishauser (30 January 1918 – 10 November 1970) was a Swiss mathematician and a pioneer of modern numerical mathematics and computer science. Life Rutishauser's father died when he was 13 years old and his mother died three years lat ...
, in the language and compiler by
Corrado Böhm Corrado Böhm (17 January 1923 – 23 October 2017) was a Professor Emeritus at the University of Rome "La Sapienza" and a computer scientist known especially for his contributions to the theory of structured programming, constructive mathemati ...
in 1951–52, in
Autocode Autocode is the name of a family of "simplified coding systems", later called programming languages, devised in the 1950s and 1960s for a series of digital computers at the Universities of Manchester, Cambridge and London. Autocode was a generic ...
of
Alick Glennie Alick Edwards Glennie (1925–2003) was a British computer scientist, most famous for having developed Autocode, which many people regard as the first ever computer compiler.Knuth, Donald E.; Pardo, Luis Trabb, "Early development of programming ...
, in the
A-2 A2, A02, A002, A², A.II or A-2 may refer to: Biology and medicine * British NVC community A2 (Lemna minor community), a plant community * A2, the second anal vein in the Comstock-Needham system of insect wing segment naming Genes and proteins * ...
system of
Grace Hopper Grace Brewster Hopper (; December 9, 1906 – January 1, 1992) was an American computer scientist, mathematician, and United States Navy Rear admiral (United States), rear admiral. One of the first programmers of the Harvard Mark I, Harvard Mar ...
, in the
Laning and Zierler system The Laning and Zierler system (sometimes called "George" by its users) was the first operating algebraic compiler, that is, a system capable of accepting mathematical formulas in algebraic notation and producing equivalent machine code (the term ...
, in the earliest proposed Fortran (1954) of
John Backus John Warner Backus (December 3, 1924 – March 17, 2007) was an American computer scientist. He directed the team that invented and implemented FORTRAN, the first widely used high-level programming language, and was the inventor of the Back ...
, in the
Autocode Autocode is the name of a family of "simplified coding systems", later called programming languages, devised in the 1950s and 1960s for a series of digital computers at the Universities of Manchester, Cambridge and London. Autocode was a generic ...
for
Mark 1 Mark 1 is the first chapter of the Gospel of Mark in the New Testament of the Christian Bible. Text The original text was written in Koine Greek. This chapter is divided into 45 verses. Textual witnesses Some early manuscripts conta ...
by
Tony Brooker Ralph Anthony Brooker (22 September 1925 – 20 November 2019), was a British computer scientist known for developing the Mark 1 Autocode. He was educated at Emanuel School and graduated in Mathematics from Imperial College in 1945 and re ...
, in ПП-2 of
Andrey Ershov Andrey Petrovich Yershov (russian: Андре́й Петро́вич Ершо́в; 19 April 1931, Moscow – 8 December 1988, Moscow) was a Soviet computer scientist, notable as a pioneer in systems programming and programming language research ...
, in BACAIC of Mandalay Grems and R. E. Porter, in Kompiler 2 of A. Kenton Elsworth and others, in ADES of E. K. Blum, the Internal Translator of
Alan Perlis Alan Jay Perlis (April 1, 1922 – February 7, 1990) was an American computer scientist and professor at Purdue University, Carnegie Mellon University and Yale University. He is best known for his pioneering work in programming languages and was t ...
, in Fortran of John Backus, in
ARITH-MATIC :''You may have been looking for arithmetic, a branch of mathematics.'' ARITH-MATIC is an extension of Grace Hopper's A-2 programming language, developed around 1955. ARITH-MATIC was originally known as A-3, but was renamed by the marketing dep ...
and
MATH-MATIC MATH-MATIC is the marketing name for the AT-3 (Algebraic Translator 3) compiler, an early programming language for the UNIVAC I and UNIVAC II. MATH-MATIC was written beginning around 1955 by a team led by Charles Katz under the direction of Grace ...
from
Grace Hopper Grace Brewster Hopper (; December 9, 1906 – January 1, 1992) was an American computer scientist, mathematician, and United States Navy Rear admiral (United States), rear admiral. One of the first programmers of the Harvard Mark I, Harvard Mar ...
's lab, in the system of Bauer and Samelson, and (in addenda in 2003 and 2009) PACT I and TRANSCODE. They then describe what kind of arithmetic was available, and provide a subjective rating of these languages on parameters of "implementation", "readability", "control structures", "data structures", "machine independence" and "impact", besides mentioning what each was the first to do.


Implementations in more recent languages


C implementation

This shows a C implementation equivalent to the above ALGOL 60. #include #include double f(double t) int main(void)


Python Python may refer to: Snakes * Pythonidae, a family of nonvenomous snakes found in Africa, Asia, and Australia ** ''Python'' (genus), a genus of Pythonidae found in Africa and Asia * Python (mythology), a mythical serpent Computing * Python (pro ...
implementation

This shows a Python implementation. from math import sqrt def f(t): return sqrt(abs(t)) + 5 * t ** 3 a = loat(input()) for _ in range(11)for i, t in reversed(list(enumerate(a))): y = f(t) print(i, "TOO LARGE" if y > 400 else y)


Rust Rust is an iron oxide, a usually reddish-brown oxide formed by the reaction of iron and oxygen in the catalytic presence of water or air moisture. Rust consists of hydrous iron(III) oxides (Fe2O3·nH2O) and iron(III) oxide-hydroxide (FeO(OH ...
implementation

This shows a Rust implementation. use std::; fn f(t: f64) -> f64 fn main()


References


External links


Implementations in many languages
at ''
Rosetta Code Rosetta Code is a wiki-based programming website with implementations of common algorithms and solutions to various programming problems in many different programming languages. It is named for the Rosetta Stone, which has the same text inscribe ...
''
Implementations in several languages
{{DEFAULTSORT:Trabb Pardo-Knuth algorithm 1977 in computing Donald Knuth Articles with example ALGOL 60 code Test items in computer languages Computer programming folklore Articles with example Python (programming language) code